﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using AForge.Imaging;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.ImageOperators;
using BrainTechLLC.ImageOperatorsNonAForgeDependent;

namespace BrainTechLLC.FilterExtensions
{
    public partial class FilterCollection : ObservableCollection<ISingleFilter>, ICanApply, INotifyPropertyChanged, IPostProcessor
    {
        protected int _currentGeneration;
        protected bool _active = true;
        protected string _collectionName;

        public FilterCollection() { }

        public new void Add(ISingleFilter filter)
        {
            base.Add(filter);
        }

        public string CollectionName
        {
            get { return _collectionName; }
            set
            {
                if (_collectionName != value)
                {
                    _collectionName = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("CollectionName"));
                }
            }
        }

        public int EnabledFiltersCount
        {
            get
            {
                // TODO - better way than to count each time
                int total = 0;

                for (int n = 0; n < Count; n++)
                {
                    var filter = this[n];

                    if ((filter.Status & FilterStatus.TempActive) == FilterStatus.TempActive ||
                        (filter.Status & FilterStatus.None) == FilterStatus.None ||
                        (filter.Status & FilterStatus.Invalid) == FilterStatus.Invalid)
                    {
                        total++;
                    }
                }

                return total;
            }
        }

        public int CurrentGeneration
        {
            get { return _currentGeneration; }
        }

        public bool Active
        {
            get { return _active; }
            set
            {
                if (_active != value)
                {
                    _active = value;
                    GotoNextGeneration(null);
                    OnPropertyChanged(new PropertyChangedEventArgs("Active"));
                }
            }
        }

        public string Name
        {
            get { return CollectionName; }
        }

        public bool Disabled
        {
            get
            {
                return (this.Count == 0 || !this.Active || this.EnabledFiltersCount == 0);
            }
        }
    }
}